package miniBanco.Mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import miniBanco.Core.TipoConcepto;
import basics.MySqlHelper;

public class TipoConceptoDao {
	MySqlHelper mySqlHelper;
	private static final String TAG = TipoCuentaDao.class.getSimpleName();
	public static final String COLUMNS = "tipoConcepto, esPositivo,Nombre";	
	
	TipoConceptoDao()
	{
		mySqlHelper = MySqlHelper.getInstance();
	}
	private StringBuilder findStatement() {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT "+COLUMNS+
				" FROM "+ getTableName()+
				" WHERE tipoConcepto = %d ");
		return sb;
	}

	private TipoConcepto doLoad(ResultSet rs) throws SQLException {
		return TipoConcepto.fromValue(rs.getInt(1));
	}
	protected TipoConcepto getByTipo(int tipo) throws SQLException {
		String sql = findStatement().toString();
		ResultSet rs = mySqlHelper.ExecuteQuery(String.format(sql, tipo), TAG);
		rs.next();
		return doLoad(rs);
	}

	protected String getTableName() {
		return "TipoConcepto";
	}
}
